#include <iostream>
#include <unistd.h>
#include "Comm.hpp"
#include<errno.h>

int main()
{
    char buffer[1024];
    SetNonBlock(0); //设置为非阻塞
    while (true)
    {
        ssize_t s = ::read(0, buffer, sizeof(buffer) - 1);
        if (s > 0)
        {
            buffer[s] = 0;

            std::cout << "Echo# " << buffer << std::endl;
        }
        else
        {
            // 两种情况要么是读取错误，要么是IO条件没有就绪
            if (errno == EWOULDBLOCK || errno == EAGAIN)
            {
                std::cout << "IO条件没有就绪, 可以做其他事情" << std::endl;
                sleep(1);
                continue;
            }
            std::cout << "读取错误... " << std::cout << "s: " << s << std::cout << "errno: " << errno << std::endl;
            sleep(1);
        }
    }
    return 0;
}